#include <iostream>
#include <cstring>
#define MAX(A,B) A>B?A:B
#define MIN(A,B) A<B?A:B
using namespace std;

int main(){
	int n;
	cin >> n;
	int array[101];
	for(int i = 1; i <= n; i++)
		cin >> array[i];
	int minScore[101][101];
	int maxScore[101][101];
	memset(&minScore, 0x7f, sizeof(minScore));
	memset(&maxScore, 0, sizeof(minScore));
	for(int i = 1; i <= n; i++)
		minScore[i][i] = maxScore[i][i] = 0;
	for(int length = 2; length <= n; length++){
		for(int i = 1; i <= n - length + 1; i++){
			int max = 0;
			int min;
			memset(&min, 0x7f, sizeof(int));
			int j = i + length - 1;
			for(int k = i; k < j; k++){
				int tempMax = maxScore[i][k] + maxScore[k+1][j];
				int tempMin = minScore[i][k] + minScore[k+1][j];
				if(tempMax > max) max = tempMax;
				if(tempMin < min) min = tempMin;
			}
			for(int k = i; k <= j; k++){
				max += array[k];
				min += array[k];
			}
			maxScore[i][j] = max;
			minScore[i][j] = min;
		}
	}
	cout << maxScore[1][n] << endl << minScore[1][n] << endl;
}
